<template>
  <a-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-item label="机构" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-depart v-decorator="['office']" :trigger-change="true"/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="报告类型">
            <j-dict-select-tag :triggerChange="true" placeholder="" ref="type" dictCode="report_type1" v-decorator="['type', validatorRules.type]" @change="typeChange"/>
          </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-item label="时间" :labelCol="labelCol" :wrapperCol="wrapperCol">

              <vue-datepicker-local v-if="this.reportType==1" style="width: 246px" ref="time" v-model="date" format="YYYY-MM"></vue-datepicker-local>

              <vue-datepicker-local v-if="this.reportType==2" style="width: 246px" ref="time" v-model="date" format="YYYY"></vue-datepicker-local>
              <j-dict-select-tag :triggerChange="true"  v-if="this.reportType==2" placeholder="" id="quarter" ref="quarter" dictCode="quarter"  v-decorator="['quarter']"/>
              <vue-datepicker-local v-if="this.reportType==3" style="width: 246px"  ref="time" v-model="date" format="YYYY"></vue-datepicker-local>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="上传报告" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload v-decorator="['filePath']" text="上传报告"></j-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>

  </a-modal>
</template>

<script>
  import VueDatepickerLocal from 'vue-datepicker-local'
  import pick from 'lodash.pick'
  import {saveReportList,editReportList } from '@/api/api'
  import JDate from '@/components/jeecg/JDate'
  // import JDateMon from '@/components/jeecg/JDateMon'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JMultiSelectTag from "@/components/dict/JMultiSelectTag"
  import JUpload from '@/components/jeecg/JUpload'
  export default {
    components: {
      VueDatepickerLocal,
      JMultiSelectTag,
      JSelectDepart,
      // JDateMon,
      JUpload,
      JDate,
    },
    name: "reportMonthModel",
    data(){
      return{
        date: '',
        reportType:'1',
        ser:{},
        form: this.$form.createForm(this),
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 16
        },
        labelRow: {
          xs: { span: 14 },
          sm: { span: 10 },
        },
        wrapperRow: {
          xs: { span: 14 },
          sm: { span: 14 },
        },
        labelRowCheckbox: {
          xs: { span: 10 },
          sm: { span: 8 },
        },
        wrapperRowCheckbox: {
          xs: { span: 10 },
          sm: { span: 14 },
        },
        dis:false,
        hiding:true,
        drawerWidth:1000,
        confirmLoading: false,
        disableSubmit:false,
        validatorRules:{
        },
        url:{
          fileUpload: window._CONFIG['domianURL']+"/sys/common/upload",
          imgerver: window._CONFIG['domianURL']+"/sys/common/view",
          add:"/jinanCloud/reportManage/add"
        }
      }
    },
    mounted() {
      this.init();
    },
    methods:{
      init(){
      },

      typeChange(e){
        console.log(e);
        this.reportType=e;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.disableSubmit = false;
      },
      add () {
        this.edit({});
      },
      edit(record){
        debugger
        this.date='';
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'date','type','office','filePath' ))
        });
      },
      handleCancel () {
        this.close()
      },
      handleSubmit () {
        debugger
        let self = this ;
        const that = this;
        let type=this.$refs.type.value;
        let date=null;
        let years;
        let date1=this.$refs.time.text;
        if(type=="2"){
          let qua=this.$refs.quarter.value;
          let text;
          if(qua !="" || qua!=undefined){
            text=self.$refs.quarter.dictOptions[qua].text
          }
            date ={date:date1+"年-"+text};
            years={years:date1};
        }else if(type =='1'){
          let date1=this.$refs.time.value;
          let year=date1.getFullYear();
          years={years:year};
          date={date:this.$refs.time.text};
        }else {
          date={date:date1};
          years={years:date1};
        }

        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let formData = Object.assign(this.model, values,date,years);
            let obj;
            // formData.type="3"
            if(!this.model.id){
              obj=saveReportList(formData);
            }else{
              obj=editReportList(formData);
            }
            obj.then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;

              that.close();
            })

          }
        })
      },
    },
  }
</script>

<style scoped>

</style>